<!DOCTYPE html>
<html lang="en"><head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1"><!-- Begin Jekyll SEO tag v2.8.0 -->
<title>0112: GTK GIO Applications - Introduction | gtkDcoding</title>
<meta name="generator" content="Jekyll v4.3.4" />
<meta property="og:title" content="0112: GTK GIO Applications - Introduction" />
<meta name="author" content="Ron Tarrant" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="This GTK Tutorial covers a D-specific implementation of Scale Widget controlling placement of a graphic element." />
<meta property="og:description" content="This GTK Tutorial covers a D-specific implementation of Scale Widget controlling placement of a graphic element." />
<link rel="canonical" href="http://localhost:4000/posts/0112-gtk-gio-application-barebones.html" />
<meta property="og:url" content="http://localhost:4000/posts/0112-gtk-gio-application-barebones.html" />
<meta property="og:site_name" content="gtkDcoding" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2021-09-03T00:00:00-04:00" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="0112: GTK GIO Applications - Introduction" />
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"BlogPosting","author":{"@type":"Person","name":"Ron Tarrant"},"dateModified":"2021-09-03T00:00:00-04:00","datePublished":"2021-09-03T00:00:00-04:00","description":"This GTK Tutorial covers a D-specific implementation of Scale Widget controlling placement of a graphic element.","headline":"0112: GTK GIO Applications - Introduction","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/posts/0112-gtk-gio-application-barebones.html"},"url":"http://localhost:4000/posts/0112-gtk-gio-application-barebones.html"}</script>
<!-- End Jekyll SEO tag -->
<link rel="stylesheet" href="../assets/main.css">
  <link rel="stylesheet" href="../css/style.css" /><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="gtkDcoding" /></head>
<body><header class="site-header" role="banner">

  <div class="wrapper"><a class="site-title" rel="author" href="../">gtkDcoding</a><nav class="site-nav">
        <input type="checkbox" id="nav-trigger" class="nav-trigger" />
        <label for="nav-trigger">
          <span class="menu-icon">
            <svg viewBox="0 0 18 15" width="18px" height="15px">
              <path d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.032C17.335,0,18,0.665,18,1.484L18,1.484z M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.032C17.335,6.031,18,6.696,18,7.516L18,7.516z M18,13.516C18,14.335,17.335,15,16.516,15H1.484 C0.665,15,0,14.335,0,13.516l0,0c0-0.82,0.665-1.483,1.484-1.483h15.032C17.335,12.031,18,12.695,18,13.516L18,13.516z"/>
            </svg>
          </span>
        </label>

        <div class="trigger"><a class="page-link" href="../about.html">About</a><a class="page-link" href="../index-reverse.html">Posts in Date Order</a><a class="page-link" href="../topics.html">Blog Posts by Topic</a></div>
      </nav></div>
</header>
<main class="page-content" aria-label="Content">
      <div class="wrapper">
        <article class="post h-entry" itemscope itemtype="http://schema.org/BlogPosting">
	<header class="post-header">
		<link rel="stylesheet" href="../css/font_size.css" />
		<link rel="stylesheet" href="../css/figure.css" />
		<link rel="stylesheet" href="../css/topics/app.css" />  <!-- sub in the tag/topic -->
		<link rel="stylesheet" href="../css/modal.css" />
		<link rel="stylesheet" href="../css/post.css" />
		<link rel="stylesheet" href="../css/mascot_effects.css" />

		
		
		<p class="post-meta">
		<time class="dt-published" datetime="2021-09-03T00:00:00-04:00" itemprop="datePublished">Friday, September 3, 2021
		</time>• by <span itemprop="author" itemscope itemtype="http://schema.org/Person"><span class="p-author h-card" itemprop="name">Ron Tarrant</span></span></p>
	</header>

	<div class="post-content e-content" itemprop="articleBody">
		<div class="skew-line"></div>
		<h2 id="after-the-hiatus">After the Hiatus</h2>

<p>It’s been more than a year since I made my last post on this blog. When I stopped posting last year, I was burned out, distracted by COVID-19, our tiny apartment was suddenly a hub of work activity for both of us, and I was still disheartened by the changes being made to <em>GTK</em> in version 4.</p>

<p>Now, I can see things a little more clearly… sort of. COVID-19 is still here and we may all go into (at least) one more round of lock-downs. But, other things are advancing…</p>

<p>My wife and I have both been double-vaccinated and we’ve worked out an arrangement whereby we can both work in this tiny apartment without driving each other up the wall.</p>

<p>Thirteen days ago, Mike Wey released GtkD 4, but the articles I’ve got on the go are all centred around GtkD 3.9. And frankly, I’m not sure I want to update to 4 because the <em>GTK</em> team dropped window position handling. Yes, it’s a small thing, but I see a problem with this…</p>

<p>The <em>GTK</em> team members believe window positions should be handled by the OS’s window manager. I do agree with them except for one thing: not all window managers remember window positions. I use three monitors, so this is kind of important to me. I like my applications to open in the last place I used them so I don’t have to search miles of screen real estate to find them.</p>

<p>So, with that in mind, I’d like to hear from you. Is anyone still interested in articles about GtkD 3.x? Please let me know in the comments below.</p>

<p>And with all that said, let’s dig into today’s article.</p>

<h2 id="0112-gtk-gio-applications---introduction">0112: GTK GIO Applications - Introduction</h2>

<p>Up ‘til now, every example has been built up from a <code class="language-plaintext highlighter-rouge">MainWindow</code> widget and a <code class="language-plaintext highlighter-rouge">Main</code> struct, both of which are instantiated in the standard entry point function, <code class="language-plaintext highlighter-rouge">main()</code>. (<em>Note: <code class="language-plaintext highlighter-rouge">TestRigWindow</code>—the actual object we’ve been instantiating in our examples—inherits from <code class="language-plaintext highlighter-rouge">MainWindow</code>, so it amounts to the same thing.</em>) But today, we’re looking at an alternative way of building applications, this time using the <em>GTK/GIO</em> <code class="language-plaintext highlighter-rouge">Application</code> class modules.</p>

<p>I’d like to point out that I didn’t stutter in that last sentence. There are two <code class="language-plaintext highlighter-rouge">Application</code> modules… the <em>GIO</em> <code class="language-plaintext highlighter-rouge">Application</code> is the parent class and the <em>GTK</em> class is derived from it. This can be a bit confusing when it comes time to write code because both modules need to be imported if we want to handle <em>GIO</em> signals. But, there’s a simple way to keep them straight, so let’s just dive in.</p>

<h2 id="why-application">Why Application?</h2>

<p>The <code class="language-plaintext highlighter-rouge">Application</code> is a more flexible framework for writing software. It doesn’t just give us the tools for building classic GUI-based software, it makes several other project types possible:</p>

<ul>
  <li>a GUI front-end for a background service,</li>
  <li>the background service itself,</li>
  <li>remote applications controlled locally,</li>
  <li>local applications controlled remotely, and</li>
  <li>a GUI-less command line application (the kind intended to be run from a terminal).</li>
</ul>

<p>On top of that, a <em>GIO</em> <code class="language-plaintext highlighter-rouge">Application</code> has a signal/callback system that gives us all kinds of flexibility in how we start up our application.</p>

<p>Finally, it also gives us a system of flags we can use for all kinds of stuff including:</p>

<ol>
  <li>designating the application as a service,</li>
  <li>passing in parameters to modify the behaviour of the running software, or</li>
  <li>react to the existence of environment variables on the computer where the application is running.</li>
</ol>

<h2 id="old-method-vs-new">Old Method vs. New</h2>

<p>The biggest difference between the <code class="language-plaintext highlighter-rouge">MainWindow</code> approach and this one is this…</p>

<p>In the <code class="language-plaintext highlighter-rouge">Application</code> paradigm, signals are used to associate callbacks with such things as <code class="language-plaintext highlighter-rouge">activate</code>, <code class="language-plaintext highlighter-rouge">startup</code>, and <code class="language-plaintext highlighter-rouge">shutdown</code>. In the paradigm we’ve been using ‘til now, <code class="language-plaintext highlighter-rouge">Main.init()</code>, <code class="language-plaintext highlighter-rouge">Main.run()</code>, and <code class="language-plaintext highlighter-rouge">Main.quit()</code> (respectively) take care of these things. Nothing new is going on here, but responsibility for application-level stuff has shifted from a <em>C</em>-style struct (<code class="language-plaintext highlighter-rouge">Main</code>) to a <em>D</em>-style object (<code class="language-plaintext highlighter-rouge">Application</code>).</p>

<h3 id="mainwindow-vs-applicationwindow">MainWindow vs. ApplicationWindow</h3>

<p>In the classical construction method, <code class="language-plaintext highlighter-rouge">MainWindow</code> acts as a top-level container for our program, but the <em>GTK/GIO</em> <code class="language-plaintext highlighter-rouge">Application</code> instead uses the <code class="language-plaintext highlighter-rouge">ApplicationWindow</code> as its primary UI container. They both inherit from <code class="language-plaintext highlighter-rouge">Window</code>, so we still get pretty much the same functionality. But the <em>GTK/GIO</em> <code class="language-plaintext highlighter-rouge">Application</code> construction method adds such things as window <code class="language-plaintext highlighter-rouge">ID</code>s, a pop-up help window for keyboard shortcuts, and a mechanism to handle how and when a <code class="language-plaintext highlighter-rouge">Menu</code> or <code class="language-plaintext highlighter-rouge">Menubar</code> is displayed. More on these as we go along, but for now, let’s dig into a barebones example…</p>

<h2 id="working-with-giogtk-applications">Working with GIO/GTK Applications</h2>

<!-- 0, 1 -->
<!-- first occurrence of application and terminal screen shots on a single page -->
<div class="screenshot-frame">
	<div class="frame-header">
		Results of this example:
	</div>
	<div class="frame-screenshot">
		<figure>
			<img id="img0" src="../images/screenshots/020_app/app_01.png" alt="Current example output" />		<!-- img# -->
			
			<!-- Modal for screenshot -->
			<div id="modal0" class="modal">																	<!-- modal# -->
				<span class="close0">&times;</span>															<!-- close# -->
				<img class="modal-content" id="img00" />															<!-- img## -->
				<div id="caption"></div>
			</div>
			
			<script>
			// Get the modal
			var modal = document.getElementById("modal0");														// modal#
			
			// Get the image and insert it inside the modal - use its "alt" text as a caption
			var img = document.getElementById("img0");															// img#
			var modalImg = document.getElementById("img00");													// img##
			var captionText = document.getElementById("caption");

			img.onclick = function()
			{
			  modal.style.display = "block";
			  modalImg.src = this.src;
			  captionText.innerHTML = this.alt;
			}
			
			// Get the <span> element that closes the modal
			var span = document.getElementsByClassName("close0")[0];											// close#
			
			// When the user clicks on <span> (x), close the modal
			span.onclick = function()
			{ 
				modal.style.display = "none";
			}
			</script>
			<figcaption>
			Current example output
			</figcaption>
		</figure>
	</div>

	<div class="frame-terminal">
		<figure class="right">
			<img id="img1" src="../images/screenshots/020_app/app_01_term.png" alt="Current example terminal output" />		<!-- img#, filename -->

			<!-- Modal for terminal shot -->
			<div id="modal1" class="modal">																				<!-- modal# -->
				<span class="close1">&times;</span>																		<!-- close# -->
				<img class="modal-content" id="img11" />																		<!-- img## -->
				<div id="caption"></div>
			</div>
			
			<script>
			// Get the modal
			var modal = document.getElementById("modal1");																	// modal#
			
			// Get the image and insert it inside the modal - use its "alt" text as a caption
			var img = document.getElementById("img1");																		// img#
			var modalImg = document.getElementById("img11");																// img##
			var captionText = document.getElementById("caption");

			img.onclick = function()
			{
			  modal.style.display = "block";
			  modalImg.src = this.src;
			  captionText.innerHTML = this.alt;
			}
			
			// Get the <span> element that closes the modal
			var span = document.getElementsByClassName("close1")[0];														// close#
			
			// When the user clicks on <span> (x), close the modal
			span.onclick = function()
			{ 
				modal.style.display = "none";
			}
			</script>

			<figcaption>
				Current example terminal output (click for enlarged view)
			</figcaption>
		</figure>
	</div>

	<div class="frame-footer">																								<!-- ------------- filename (below) --------- -->
		The code file for this example is available <a href="https://github.com/rontarrant/gtkd_demos/blob/master/020_app/app_01_barebones.d" target="_blank">here</a>.
	</div>
</div>
<!-- end of snippet for first (1st) occurrence of application and terminal screen shots on a single page -->

<p>Right up front, naturally, we need to do some imports to get all this working. But because the <em>GTK</em> and <em>GIO</em> modules are both named <code class="language-plaintext highlighter-rouge">Application</code>, we need to put some extra effort into keeping them straight. That’s done with <em>D</em>’s aliasing feature:</p>

<div class="language-d highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="n">gio</span><span class="p">.</span><span class="n">Application</span> <span class="p">:</span> <span class="n">GioApplication</span> <span class="p">=</span> <span class="n">Application</span><span class="p">;</span>
<span class="k">import</span> <span class="n">gtk</span><span class="p">.</span><span class="n">Application</span> <span class="p">:</span> <span class="n">GtkApplication</span> <span class="p">=</span> <span class="n">Application</span><span class="p">;</span>
<span class="k">import</span> <span class="n">gtk</span><span class="p">.</span><span class="n">ApplicationWindow</span><span class="p">;</span>
</code></pre></div></div>

<p>Alias names are up to you, of course, but for this demonstration, I’m emphasizing clarity of function.</p>

<h3 id="how-main-differs">How main() Differs</h3>

<p>In the classical construction method, our <code class="language-plaintext highlighter-rouge">main()</code> function had to do a few things before handing control over to the <code class="language-plaintext highlighter-rouge">Main</code> <code class="language-plaintext highlighter-rouge">struct</code>… I’m pointing this out because, as it turns out, <code class="language-plaintext highlighter-rouge">Main</code> is a <code class="language-plaintext highlighter-rouge">struct</code>, not a <code class="language-plaintext highlighter-rouge">class</code>. It’s the reason we don’t sub-class it into <code class="language-plaintext highlighter-rouge">MyMain</code> or some-such in order to move its definition outside of the <code class="language-plaintext highlighter-rouge">main()</code> function.</p>

<p>With the <em>GTK/GIO</em> <code class="language-plaintext highlighter-rouge">Application</code> construction method, however, we don’t have this restriction, so <code class="language-plaintext highlighter-rouge">main()</code> only has to do one thing, instantiate the <em>GTK</em> <code class="language-plaintext highlighter-rouge">Application</code> object:</p>

<div class="language-d highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">void</span> <span class="n">main</span><span class="p">(</span><span class="nb">string</span><span class="p">[]</span> <span class="n">args</span><span class="p">)</span>
<span class="p">{</span>
	<span class="n">MyApplication</span> <span class="n">thisApp</span> <span class="p">=</span> <span class="k">new</span> <span class="n">MyApplication</span><span class="p">(</span><span class="n">args</span><span class="p">);</span>
	
<span class="p">}</span> <span class="c1">// main()</span>
</code></pre></div></div>

<p>Note that it passes any command-line arguments along to the <code class="language-plaintext highlighter-rouge">MyApplication</code> constructor, another change from the old way of doing things in which we passed them to <code class="language-plaintext highlighter-rouge">Main.init()</code>. And keep in mind, <code class="language-plaintext highlighter-rouge">MyApplication</code> is derived from the <em>GTK</em> <code class="language-plaintext highlighter-rouge">Application</code> object, not its <em>GIO</em> namesake.</p>

<p>Speaking of which, let’s have a look at this sub-class…</p>

<h3 id="myapplication-a-gtk-application-lovechild">MyApplication, a GTK Application Lovechild</h3>

<p>The preamble looks like this:</p>

<div class="language-d highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="n">MyApplication</span> <span class="p">:</span> <span class="n">GtkApplication</span>
<span class="p">{</span>
	<span class="n">ApplicationFlags</span> <span class="n">flags</span> <span class="p">=</span> <span class="n">ApplicationFlags</span><span class="p">.</span><span class="n">FLAGS_NONE</span><span class="p">;</span>
	<span class="nb">string</span> <span class="n">id</span> <span class="p">=</span> <span class="kc">null</span><span class="p">;</span> <span class="c1">// if application uniqueness isn't important</span>
</code></pre></div></div>

<p>In order to call the super-class constructor, we need two things:</p>

<ul>
  <li>one or more flags to set up the <code class="language-plaintext highlighter-rouge">Application</code>’s type and abilities, and</li>
  <li>an <code class="language-plaintext highlighter-rouge">ID</code> in the form of a string.</li>
</ul>

<p>Now, you’ll note that this particular example has <code class="language-plaintext highlighter-rouge">id</code> set to <code class="language-plaintext highlighter-rouge">null</code>. That’s because, if we really don’t care about <code class="language-plaintext highlighter-rouge">Application</code> uniqueness, we don’t have to supply an <code class="language-plaintext highlighter-rouge">ID</code>. In the next example, we’ll talk more about this, but for now, let’s move on to…</p>

<h3 id="the-myapplication-constructor">The MyApplication Constructor</h3>

<p>This is where we set up the <code class="language-plaintext highlighter-rouge">Application</code> and get things going:</p>

<div class="language-d highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">this</span><span class="p">(</span><span class="nb">string</span><span class="p">[]</span> <span class="n">args</span><span class="p">)</span>
<span class="p">{</span>
	<span class="k">super</span><span class="p">(</span><span class="n">id</span><span class="p">,</span> <span class="n">flags</span><span class="p">);</span>
	<span class="n">addOnActivate</span><span class="p">(&amp;</span><span class="n">onActivate</span><span class="p">);</span>
	<span class="n">run</span><span class="p">(</span><span class="n">args</span><span class="p">);</span>
		
<span class="p">}</span> <span class="c1">// this()</span>
</code></pre></div></div>

<p>The first line isn’t all that different from what we’re used to. We call the super-class constructor, passing it the <code class="language-plaintext highlighter-rouge">id</code> and <code class="language-plaintext highlighter-rouge">flags</code> variables. In this example, because <code class="language-plaintext highlighter-rouge">id</code> is <code class="language-plaintext highlighter-rouge">null</code> and our <code class="language-plaintext highlighter-rouge">flags</code> variable is <code class="language-plaintext highlighter-rouge">NONE</code>, we aren’t asking anything of the super-class constructor except to start the application.</p>

<p>The next line, however, is a departure from the old method we’ve been using. I’m sure you recognize the function naming convention even if you don’t know the <code class="language-plaintext highlighter-rouge">addOnActivate()</code> function itself. It’s a signal hook-up, as you’ve likely already guessed. Why it’s there is because (and you might wanna make an extra-large mental note of this):</p>

<p><em>Application actions are processed via signals and callbacks.</em></p>

<p>This means the <em>GIO/GTK</em> <code class="language-plaintext highlighter-rouge">Application</code> construction approach brings external operations directly under the control of a single, high-level entity, the <code class="language-plaintext highlighter-rouge">Application</code> object. I’m talking about things like window and accelerator management… or OS-related tasks such as handling command-line arguments, starting up, shutting down… In other words, because the uppercase-A <code class="language-plaintext highlighter-rouge">Application</code> handles all things external, the lowercase-a application (in other words: our code) doesn’t need to be aware of them. There’s no mixing of internal and external operations and therefore better separation of code.</p>

<p>Looking at the last line, we find another way this new application construction method differs from the old. The command-line arguments—instead of being passed to an <code class="language-plaintext highlighter-rouge">init()</code> function—are passed to the <code class="language-plaintext highlighter-rouge">run()</code> function.</p>

<p>What’s the difference? Not much, actually. Both <code class="language-plaintext highlighter-rouge">Main.init()</code> and <code class="language-plaintext highlighter-rouge">Gio.Application.run()</code> count the number of command-line arguments and build a string array with one element per argument. The biggest difference here is that <code class="language-plaintext highlighter-rouge">Main</code> is a <em>C</em> struct whereas <code class="language-plaintext highlighter-rouge">Gio.Application</code> is a proper class and is more consistent with the <em>OOP</em> paradigm we’ve been using in every example posted on this blog.</p>

<h3 id="the-onactivate-callback">The onActivate Callback</h3>

<p>This is the only place, in a simple application, where we need to reference the <code class="language-plaintext highlighter-rouge">Gio.Application</code> module:</p>

<div class="language-d highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">void</span> <span class="n">onActivate</span><span class="p">(</span><span class="n">GioApplication</span> <span class="n">app</span><span class="p">)</span> <span class="c1">// non-advanced syntax</span>
<span class="p">{</span>
        <span class="n">AppWindow</span> <span class="n">appWindow</span> <span class="p">=</span> <span class="k">new</span> <span class="n">AppWindow</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
		
<span class="p">}</span> <span class="c1">// onActivate()</span>
</code></pre></div></div>

<p>This is because the <code class="language-plaintext highlighter-rouge">addOnActivate()</code> function lives in that module. There are other signal hook-up functions in <code class="language-plaintext highlighter-rouge">Gtk.Application</code> and, of course, <code class="language-plaintext highlighter-rouge">Gtk.Application</code> inherits from <code class="language-plaintext highlighter-rouge">Gio.Application</code>, but when hooking up signals—just as we’ve seen elsewhere—we need to declare the arguments to be exactly what they are in the wrapper file.</p>

<p>We have one last class to look at…</p>

<h3 id="the-appwindow-class">The AppWindow Class</h3>

<p>This class, as mentioned above, inherits from <code class="language-plaintext highlighter-rouge">ApplicationWindow</code> which in turn inherits from <em>GTK</em> <code class="language-plaintext highlighter-rouge">Window</code> which means for the most part, it’s just another <code class="language-plaintext highlighter-rouge">Window</code>. It does have a few features not found in the generic <em>GTK</em> <code class="language-plaintext highlighter-rouge">Window</code>, however, things like:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">ID</code>s to make window management easier,</li>
  <li>help overlays (more on these in a moment), and</li>
  <li>hideable menubars.</li>
</ul>

<p>The first—<code class="language-plaintext highlighter-rouge">ID</code>s—is more or less self-explanatory. The <code class="language-plaintext highlighter-rouge">Application</code> uses <code class="language-plaintext highlighter-rouge">ApplicationWindow</code> <code class="language-plaintext highlighter-rouge">ID</code>s for window management. <code class="language-plaintext highlighter-rouge">Window</code>s can be added, removed… you get the idea.</p>

<p>Help overlays, however, aren’t something we’ll find in the old construction method. These are inspired by mobile apps where the help screen slides in over top of the <code class="language-plaintext highlighter-rouge">ApplicationWindow</code> and slides back out when we’re done with it.</p>

<p>Hideable <code class="language-plaintext highlighter-rouge">Menubars</code> are also inspired by mobile apps, although they’re becoming more prevalent on desktops as well.</p>

<p>Anyway, that’s all nice in theory, but how about a look at the code:</p>

<div class="language-d highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="n">AppWindow</span> <span class="p">:</span> <span class="n">ApplicationWindow</span>
<span class="p">{</span>
	<span class="kt">int</span> <span class="n">width</span> <span class="p">=</span> <span class="mi">400</span><span class="p">,</span> <span class="n">height</span> <span class="p">=</span> <span class="mi">200</span><span class="p">;</span>
	<span class="nb">string</span> <span class="n">title</span> <span class="p">=</span> <span class="s">"Barebones Application"</span><span class="p">;</span>
	
	<span class="k">this</span><span class="p">(</span><span class="n">MyApplication</span> <span class="n">myApp</span><span class="p">)</span>
	<span class="p">{</span>
		<span class="k">super</span><span class="p">(</span><span class="n">myApp</span><span class="p">);</span>
		<span class="n">setSizeRequest</span><span class="p">(</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">);</span>
		<span class="n">setTitle</span><span class="p">(</span><span class="n">title</span><span class="p">);</span>
		<span class="n">showAll</span><span class="p">();</span>
		
	<span class="p">}</span> <span class="c1">// this()</span>
	
<span class="p">}</span> <span class="c1">// class AppWindow</span>
</code></pre></div></div>

<p>As with run-of-the-mill <code class="language-plaintext highlighter-rouge">Window</code>s or <code class="language-plaintext highlighter-rouge">MainWindow</code>s, we set up dimensions and a title in the preamble, then in the constructor we call the super-class constructor, set the size, the title, and then call <code class="language-plaintext highlighter-rouge">showAll()</code>. The only thing here that departs from the old construction method is setting up an <code class="language-plaintext highlighter-rouge">Application</code> pointer which we pass to the super-class constructor, so what’s up with that?</p>

<p>Not a lot, really. We’re setting up an association between the <code class="language-plaintext highlighter-rouge">ApplicationWindow</code> and the <em>GIO/GTK</em> <code class="language-plaintext highlighter-rouge">Application</code> so the <code class="language-plaintext highlighter-rouge">Application</code> can manage the <code class="language-plaintext highlighter-rouge">ApplicationWindow</code>. Makes sense, right?</p>

<h2 id="conclusion">Conclusion</h2>

<p>Anyway, that’s all for today. This should give you a basic understanding of what’s going on behind the curtain when you use this alternate application construction method.</p>

<p>Next time, we’ll dig a little deeper. See you then.</p>

<div class="blog-nav">
	<div style="float: left;">
		<a href="./0111-graphic-position-scale-button.html">Previous: Control Graphic Position with Scale Button</a>
	</div>
	<div style="float: right;">
		<a href="./0113-gtk-gio-application-ids-signals.html">Next: GTK/GIO Application II - Application ID</a>
	</div>
</div>

<p>
	<h3></h3>
<div class="inpage-frame">
	<a href="https://github.com/sponsors/rontarrant">
		<BR>
		<BR>
		<B>Is this article useful? Educational? Entertaining, perhaps?</B>
		<BR>
		<figure class="left">
			<img src="../images/favorite_32.png" alt="Sponsorship heart" style="width: 32px; height: 32px;">
		</figure>
		You're free to accept or decline this invitation to become our newest sponsor.
	</a>
</div>
	<h4 class="comment-blurb"><B>Comments? Questions? Observations?</B></h4>
	<p>
		Did we miss a tidbit of information that would make this post even more informative? Let's talk about it in the comments.
	</p>
	<script src="https://utteranc.es/client.js"
		repo="rontarrant"
		issue-term="pathname"
		theme="github-light"
		crossorigin="anonymous"
		async>
	</script>
	<ul>
		<li> come on over to the <a href="https://forum.dlang.org/">D Language Forum</a> and look for one of the <i>gtkDcoding</i> announcement posts, </li>
		<li> drop by <a href="https://forum.gtkd.org/">the <i>GtkD Forum</i></a>,</li>
		<li> follow the link below to email me, or</li>
		<li> go to the	<a href="https://www.facebook.com">gtkDcoding Facebook page.</a></li>
	</ul>
</p>
<p> You can also subscribe <a href="/feed.xml">via RSS</a> so you won't miss anything. Thank you very much for dropping by.</p>
<p>&copy; Copyright 2025 Ron Tarrant </p>
</div>

	<a class="u-url" href="./0112-gtk-gio-application-barebones.html" hidden></a>
</article>

      </div>
    </main><footer class="site-footer h-card">
  <data class="u-url" href="/"></data>

  <div class="wrapper">

    <h2 class="footer-heading">gtkDcoding</h2>

    <div class="footer-col-wrapper">
      <div class="footer-col footer-col-1">
        <ul class="contact-list">
          <li class="p-name">Ron Tarrant</li><li><a class="u-email" href="mailto:gtkDcoding@gmail.com">gtkDcoding@gmail.com</a></li></ul>
      </div>

      <div class="footer-col footer-col-2"><ul class="social-media-list"><li><a href="https://github.com/rontarrant"><svg class="svg-icon"><use xlink:href="../assets/minima-social-icons.svg#github"></use></svg> <span class="username">rontarrant</span></a></li></ul>
</div>

      <div class="footer-col footer-col-3">
        <p>Simple examples of how to use GtkD to build GUI applications.</p>
      </div>
    </div>

  </div>

</footer>
</body>

</html>
